package trong.gold.soft.com.view;

import trong.gold.soft.com.main.mTetrisMidlet;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import trong.gold.soft.com.model.Resources;
import trong.gold.soft.com.model.createImg;
import trong.gold.soft.com.model.mediaGame;
import trong.gold.soft.com.model.font.VietnameseFont;

public class settingTetris extends Canvas{
	private String ttName = "thong-tin.png";
	private String backName = "back.png";
	private String chonName = "chon.png";
	private String ncd = "Cài đặt";
	private String bat="Đang bật",tat="Đang tắt";
	private String nsoundName = "noSound.png",soundName="sound.png";
	private Image ktin,backgrImage,backImage,soundImg,nosoundImg,chonImg;
	
	private mTetrisMidlet midlet;
	public settingTetris(mTetrisMidlet midlet){
		this.midlet = midlet;
		backgrImage = createImg.createImage("/com/image/" + Resources.backgrName);
		ktin = createImg.createImage("/com/image/" + ttName);
		backImage = createImg.createImage("/com/image/process/" + backName);
		soundImg = createImg.createImage("/com/image/process/" + soundName);
		nosoundImg = createImg.createImage("/com/image/process/" + nsoundName);
		chonImg = createImg.createImage("/com/image/process/" + chonName);
	}
	protected void paint(Graphics g) {
		setFullScreenMode(true);
		g.drawImage(backgrImage, 0, 0, Resources.TOP_LEFT_ANCHOR);
		g.setColor(0xd8fbb6);
		g.fillRect(0, this.getHeight() - 25, this.getWidth(), 25);
		g.drawImage(ktin, 0, this.getHeight() - 25, Graphics.BOTTOM | Graphics.LEFT);
		g.drawImage(backImage, this.getWidth() - 5, this.getHeight(), Graphics.BOTTOM | Graphics.RIGHT);
		g.drawImage(chonImg, 5, this.getHeight(), Graphics.BOTTOM | Graphics.LEFT);
		VietnameseFont.BlackBold.DrawString(g, ncd,this.getWidth()/2,this.getHeight() - ktin.getHeight(), Graphics.HCENTER);
		if(getsound()){
			g.drawImage(soundImg, this.getWidth()/3 - soundImg.getWidth(), this.getHeight() - ktin.getHeight()/2 - 25, Resources.TOP_LEFT_ANCHOR);
			VietnameseFont.BlackBold.DrawString(g, bat,this.getWidth()/3 + 5 + soundImg.getWidth()*2,this.getHeight() - ktin.getHeight()/2 - 25 + soundImg.getHeight()/3, Graphics.HCENTER);
		}else{
			g.drawImage(nosoundImg, this.getWidth()/3 - nosoundImg.getWidth(), this.getHeight() - ktin.getHeight()/2 - 25, Resources.TOP_LEFT_ANCHOR);
			VietnameseFont.BlackBold.DrawString(g, tat,this.getWidth()/3 + 5 + nosoundImg.getWidth()*2,this.getHeight() - ktin.getHeight()/2 - 25 + nosoundImg.getHeight()/3, Graphics.HCENTER);
			
		}
			
	}
	private boolean getsound(){
		return slSound.getsound();
	}
	private boolean setsound(){
		return slSound.setsound();
	}
	private mediaGame getmedia(){
		return slSound.getmedia();
		
	}
	public void keyPressed(int keyCode) {
		
		switch (keyCode) {
		case -1:
			
			break;
		case -2:
			
			break;
		case -5:
			break;
		case -7:
			setnull();
			Runtime.getRuntime().gc();
			midlet.switchState(this,new menuTetris(midlet));
			break;
		case -6:
			if(getsound()){
				setsound();
				repaint();
				getmedia().stopMedia();
			}else{
				setsound();
				repaint();
				getmedia().startMedia();
			}
				
			break;
		}
	}
	private void setnull(){
		ttName=null;
		backName=null;
		nsoundName=null;
		soundName=null;
		ktin=null;
		backgrImage=null;
		backImage=null;
		soundImg=null;
		nosoundImg=null;
	}
}
